package com.wnhz.work.yz.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.wnhz.work.yz.R;
import com.wnhz.work.yz.bean.XinChengBean;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by admin on 2016/12/6.
 */
public class TravelAddressPickAdapter extends BaseAdapter {
    private Context context;
//    private List<VisitTimeBean> list = new ArrayList<>();
    private View.OnClickListener onClickListener;
    private List<XinChengBean.InfoEntity> info1 = new ArrayList<>();


    public TravelAddressPickAdapter(Context context, List<XinChengBean.InfoEntity> info1, View.OnClickListener onClickListener) {
        this.context = context;
        this.info1 = info1;
        this.onClickListener = onClickListener;
    }

    @Override
    public int getCount() {
        return info1.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        DriverPickViewHolder viewHolder = new DriverPickViewHolder();
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_travel_address, null);
            viewHolder.tv_name = (TextView) convertView.findViewById(R.id.tv_address_name);
            viewHolder.iv_select = (ImageView) convertView.findViewById(R.id.iv_address_select);
            viewHolder.rl_item_travel_address = convertView.findViewById(R.id.rl_item_travel_address);

            convertView.setTag(viewHolder);
        } else {
            viewHolder = (DriverPickViewHolder) convertView.getTag();
        }

        viewHolder.tv_name.setText(info1.get(position).getPlace() + "");

        boolean isShow = info1.get(position).isShow();
        if (isShow) {
            viewHolder.iv_select.setVisibility(View.VISIBLE);
        } else {
            viewHolder.iv_select.setVisibility(View.GONE);
        }


        viewHolder.rl_item_travel_address.setOnClickListener(onClickListener);
        viewHolder.rl_item_travel_address.setTag(position);

        return convertView;
    }


    class DriverPickViewHolder {
        TextView tv_name;
        ImageView iv_select;
        View rl_item_travel_address;
    }
}
